/*    */ package com.eptok.yspay.opensdkjava.util;
/*    */ 
/*    */ import java.security.SecureRandom;
/*    */ import javax.crypto.Cipher;
/*    */ import javax.crypto.SecretKey;
/*    */ import javax.crypto.SecretKeyFactory;
/*    */ import javax.crypto.spec.IvParameterSpec;
/*    */ import javax.crypto.spec.SecretKeySpec;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class JDES
/*    */ {
/*    */   private byte[] m_desKey;
/*    */   private static JDES instance;
/*    */   
/*    */   public static synchronized JDES getInstanse() {
/* 19 */     if (instance == null) {
/* 20 */       instance = new JDES();
/*    */     }
/* 22 */     return instance;
/*    */   }
/*    */   
/*    */   public void SetKey(byte[] desKey) {
/* 26 */     this.m_desKey = desKey;
/*    */   }
/*    */ 
/*    */   
/*    */   public byte[] doECBEncrypt(byte[] plainText, int len) throws Exception {
/* 31 */     Cipher cipher = getCipher("DES", "DES/ECB/PKCS5Padding", 1, (byte[])null);
/* 32 */     byte[] encryptedData = cipher.doFinal(plainText, 0, len);
/* 33 */     return encryptedData;
/*    */   }
/*    */ 
/*    */   
/*    */   public byte[] doECBDecrypt(byte[] encryptText, int len) throws Exception {
/* 38 */     Cipher cipher = getCipher("DES", "DES/ECB/PKCS5Padding", 2, (byte[])null);
/* 39 */     byte[] decryptedData = cipher.doFinal(encryptText, 0, len);
/* 40 */     return decryptedData;
/*    */   }
/*    */ 
/*    */   
/*    */   protected Cipher getCipher(String factory, String cipherName, int cryptMode, byte[] iv) throws Exception {
/* 45 */     SecureRandom sr = new SecureRandom();
/* 46 */     byte[] rawKeyData = this.m_desKey;
/* 47 */     SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(factory);
/* 48 */     SecretKey key = new SecretKeySpec(this.m_desKey, factory);
/* 49 */     Cipher cipher = Cipher.getInstance(cipherName);
/* 50 */     if (iv != null) {
/* 51 */       IvParameterSpec ips = new IvParameterSpec(iv);
/* 52 */       cipher.init(cryptMode, key, ips, sr);
/*    */     } else {
/* 54 */       cipher.init(cryptMode, key, sr);
/*    */     } 
/*    */     
/* 57 */     return cipher;
/*    */   }
/*    */ }


/* Location:              D:\repository\io\github\ysgatesdk\yspay-opensdk-java\1.0.1\yspay-opensdk-java-1.0.1.jar!\com\eptok\yspay\opensdkjav\\util\JDES.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */